package com.ruoyi.shop.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.ShopRefundApply;
import com.ruoyi.shop.service.IShopRefundApplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款申请Controller
 * 
 * @author Alan Zhang
 * @date 2021-10-02
 */
@Controller
@RequestMapping("/refund/apply")
public class ShopRefundApplyController extends BaseController
{
    private String prefix = "refund/apply";

    @Autowired
    private IShopRefundApplyService shopRefundApplyService;

    @RequiresPermissions("refund:apply:view")
    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询退款申请列表
     */
    @RequiresPermissions("refund:apply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopRefundApply shopRefundApply)
    {
        startPage();
        List<ShopRefundApply> list = shopRefundApplyService.selectShopRefundApplyList(shopRefundApply);
        return getDataTable(list);
    }

    /**
     * 导出退款申请列表
     */
    @RequiresPermissions("refund:apply:export")
    @Log(title = "退款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopRefundApply shopRefundApply)
    {
        List<ShopRefundApply> list = shopRefundApplyService.selectShopRefundApplyList(shopRefundApply);
        ExcelUtil<ShopRefundApply> util = new ExcelUtil<ShopRefundApply>(ShopRefundApply.class);
        return util.exportExcel(list, "退款申请数据");
    }

    /**
     * 新增退款申请
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存退款申请
     */
    @RequiresPermissions("refund:apply:add")
    @Log(title = "退款申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopRefundApply shopRefundApply)
    {
        return toAjax(shopRefundApplyService.insertShopRefundApply(shopRefundApply));
    }

    /**
     * 修改退款申请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShopRefundApply shopRefundApply = shopRefundApplyService.selectShopRefundApplyById(id);
        mmap.put("shopRefundApply", shopRefundApply);
        return prefix + "/edit";
    }

    /**
     * 修改保存退款申请
     */
    @RequiresPermissions("refund:apply:edit")
    @Log(title = "退款申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopRefundApply shopRefundApply)
    {
        return toAjax(shopRefundApplyService.updateShopRefundApply(shopRefundApply));
    }

    /**
     * 删除退款申请
     */
    @RequiresPermissions("refund:apply:remove")
    @Log(title = "退款申请", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopRefundApplyService.deleteShopRefundApplyByIds(ids));
    }
}
